'use strict'

const { db, getUsers } = require('../db_helper')

const CREATE_TABLE = `
create table users (
  user text PRIMARY KEY,
  psw  text,
  name text,
  auth text
)
`;

const SAVE_USER = 'insert into users (user, psw, name) values (?, ?, ?)'

const init = () => {
  db.serialize(function() {

    db.run(CREATE_TABLE);
    var stmt = db.prepare(SAVE_USER);
    stmt.run(['admin', '123123', '管理员']);
    stmt.run(['lianzt', '123123', '练作泰']);
    stmt.run(['jinxx', '123123', '金修祥']);
    
    stmt.finalize();

  });

  db.close();
}

const query = () => {
  db.serialize(() => {
    db.each('SELECT * FROM users', function(err, row) {
      console.log(row);
    });
  });

  db.close();
}

init();
// query();